package com.zzptc.fxh.myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zzptc.fxh.myapplication.adapter.MyAdapter;
import com.zzptc.fxh.myapplication.entity.RecipeModel;
import com.zzptc.fxh.myapplication.entity.ResultsBean;
import com.zzptc.fxh.myapplication.service.MyAppService;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    RecyclerView recyclerView;
    List<String> list=new ArrayList<>();
    private final Retrofit retrofit=new Retrofit.Builder()
            .baseUrl("https://liyuankun.cn/api/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView=findViewById(R.id.rv_caipu);

        MyAppService service = retrofit.create(MyAppService.class);
        Call<RecipeModel> call = service.getRecipe(5);
        call.enqueue(new Callback<RecipeModel>() {
            @Override
            public void onResponse(Call<RecipeModel> call, Response<RecipeModel> response) {
                RecipeModel body = response.body();
                List<ResultsBean> results=body.getResults();
                for (ResultsBean result:
                results){
                    result.save();
                }
            }

            @Override
            public void onFailure(Call<RecipeModel> call, Throwable t) {

            }
        });
        //调用方法
        MyAdapter myAdapter=new MyAdapter(MainActivity.this,list);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(MainActivity.this);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(myAdapter);
    }

}
